package com.ailk.kbi.kbirazor.common
{

	
	import flash.utils.getQualifiedClassName;
	
	import mx.collections.ArrayCollection;
	import mx.controls.Alert;
	import mx.managers.CursorManager;
	import mx.rpc.events.FaultEvent;
	
	public class Util
	{
		
		public static function isNull(value:String):Boolean{
			return value == null || value.length == 0;
		}
		
		public static function isNotNull(value:String):Boolean{
			return !isNull(value);
		}
		
		//公共的失败提示
		public static function faultHandler(event:FaultEvent):void{
			CursorManager.removeBusyCursor();
			//Alert.show(event.fault.faultString + event.fault.message,"错误");
			Alert.show(event.fault.faultString,"错误");
		}
		
		public static function addAll(base:ArrayCollection, src:ArrayCollection):void{
			if(src != null){
				base.addAll(src);
			}			
		}
		
		public static function getModeAttribute(xmlList:*, key:String):String{
			var value : String;	
			/*从属性读取该值*/
			if(xmlList.hasOwnProperty("@" + key)){
				value = xmlList.attribute(key);
			}
			
			var valueParam : String = getModeParam(xmlList, key);
			if(isNotNull(valueParam)){
				value = valueParam;
			}
			return value;
		}
		
		public static function getModeElement(xmlList:*, key:String):String{
			var value : String;	
			/*从属性读取该值*/
			if(xmlList.hasOwnProperty(key)){
				value = xmlList.elements(key);
			}
			
			var valueParam : String = getModeParam(xmlList, key);
			if(isNotNull(valueParam)){
				value = valueParam;
			}
			return value;
		}
		
		public static function getModeParam(xmlList:*, key:String):String{
			var value : String;	
			
			/*从参数读取该值*/
			var paramXML:XMLList = xmlList.param.(@name == key);			
			if(paramXML){
				/*通用的配置*/
				var valueCommonXML:XMLList = paramXML.value.(!hasOwnProperty('@mode'));
				if(valueCommonXML){
					value = valueCommonXML;
				}
				
				/*指定模式的配置*/
				var valueModeXML:XMLList = paramXML.value.(@mode.indexOf(SettingModel.getInstance().settingVO.mode) > -1)
				if(valueModeXML){
					value = valueModeXML;
				}
			}
			return value;
		}
		
	}
}